package com.caac.core.web.action.common;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caac.core.config.Config;
import com.caac.core.config.Monitor;
import com.caac.core.config.MonitorSession;
import com.caac.core.config.OnlineUsers;
import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;
import com.caac.core.web.listener.SessionListener;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright caac 2004</p>
 * <p>Company: caac</p>
 * @author <a href="mailto:project@caac.com.cn">Project Group</a>
 * @version 1.0
 */

public class MonitorAction extends BaseAction {
    protected ActionForward doExecute(ActionMapping mapping,
                                      BaseForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response) throws
            Exception {
        Monitor monitor = Monitor.getInstance();
        monitor.init();
        MonitorSession ms = new MonitorSession();

        ms.setCurrentCount(SessionListener.getCurrentCount());
        ms.setMaxCount(SessionListener.getMaxCount());
        ms.setMaxInactiveInterval(SessionListener.getMaxInactiveInterval());
        ms.setTotalCount(SessionListener.getTotalCount());

        ms.setMaxMemory(monitor.getMaxMemory());
        ms.setPercentFree(monitor.getPercentFree());
        ms.setTotalMemory(monitor.getTotalMemory());
        ms.setUsedMemory(monitor.getUsedMemory());
        ms.setActiveThreadCount(monitor.getActiveThreadCount());
        ms.setStartupTime(Config.getInstance().getStartupTime());

        request.setAttribute("dmView", ms);
        request.setAttribute("sysData", OnlineUsers.getInstance().getUsers());
        return forward(mapping);
    }
}
